%function evaluationFigure(type)
clc;
clear;
close all;

filenames = ["test1", "test2", "test3", "testMdis", "testMdis2", "lub"];
type = 4;

%%HMM-SVM
if type == 0
    a = [0; 0];
    b = [0; 0];
    c = [0; 0];
    d = [0; 0];
    for i = 1: length(filenames)
        m = load("result/result-" + filenames(i) + ".mat");
        result = m.result;
        m = load("result/SVMresult-" + filenames(i) + ".mat");
        SVMresult = m.result;
        m = load("new_data/" + filenames(i) + ".mat");
        label = m.label;
        for j = 1: length(label)
            if result(j) == 1 && label(j) == 1
                a(1) = a(1) + 1;
            elseif result(j) ~= 1 && label(j) == 1
                c(1) = c(1) + 1;
            elseif result(j) == 1 && label(j) ~= 1
                b(1) = b(1) + 1;
            elseif result(j) ~= 1 && label(j) ~= 1
                d(1) = d(1) + 1;
            end
            
            if SVMresult(j) == 1 && label(j) == 1
                a(2) = a(2) + 1;
            elseif SVMresult(j) ~= 1 && label(j) == 1
                c(2) = c(2) + 1;
            elseif SVMresult(j) == 1 && label(j) ~= 1
                b(2) = b(2) + 1;
            elseif SVMresult(j) ~= 1 && label(j) ~= 1
                d(2) = d(2) + 1;
            end
        end
    end  
    
    figure;

    color1 = [0 .3 .7];
    color2 = [.8 .1 .1];
    size = 18;

    x = [1; 2];
    TPR = a./(a+c);
    FPR = b./(b+d);
    y = [TPR, FPR];
    z = bar(x, y);

    set(z(1), 'FaceColor', color1);
    set(z(2), 'FaceColor', color2);
    ylabel('TPR / FPR');
    set(get(gca,'XLabel'),'FontSize',size);
    set(get(gca,'YLabel'),'FontSize',size);
    set(gca,'FontSize',size);
    set(gca,'xticklabel',{'HMM+SVM','SVM'});
    legend('TPR', 'FPR', 'Location', 'NorthEast');
    ylim([0 1]);
end

%%TPR-Volume (water lub)
if type == 2
    %figure;
    %% Water
   % subplot(1, 2, 1);
    m = load("result/result-" + filenames(type) + ".mat");
    result = m.result;
    m = load("new_data/" + filenames(type) + ".mat");
    label = m.label;
    volume = m.v;
    
    a = [0; 0; 0];
    b = [0; 0; 0];
    c = [0; 0; 0];
    d = [0; 0; 0];
    
    xUnit = 10;
    
    for i = 1: length(label)
        if result(i) == 1 && label(i) == 1
            a(volume(i)/xUnit) = a(volume(i)/xUnit) + 1;
        elseif result(i) ~= 1 && label(i) == 1
            c(volume(i)/xUnit) = c(volume(i)/xUnit) + 1;
        elseif result(i) == 1 && label(i) ~= 1
            b(volume(i)/xUnit) = b(volume(i)/xUnit) + 1;
        elseif result(i) ~= 1 && label(i) ~= 1
            d(volume(i)/xUnit) = d(volume(i)/xUnit) + 1;
        end
    end

    color1 = [0 .3 .7];
    color2 = [.8 .1 .1];
    size = 18;

    x = [10; 20; 30];
    TPR = a./(a+c);
    FPR = b./(b+d);
    y = [TPR, FPR];
    z = bar(x, y);

    set(z(1), 'FaceColor', color1);
    set(z(2), 'FaceColor', color2);
    xlabel('Water Volume (mL)');
    ylabel('TPR / FPR');
    set(get(gca,'XLabel'),'FontSize',size);
    set(get(gca,'YLabel'),'FontSize',size);
    set(gca,'FontSize',size);
    legend('TPR', 'FPR', 'Location', 'NorthEast');
    ylim([0 1]);
    %% Lub
    %subplot(1, 2, 2);
    %figure;
    m = load("result/result-" + filenames(type+4) + ".mat");
    result = m.result;
    m = load("new_data/" + filenames(type+4) + ".mat");
    label = m.label;
    volume = m.v;
    
    a = [0; 0; 0];
    b = [0; 0; 0];
    c = [0; 0; 0];
    d = [0; 0; 0];
    
    xUnit = 10;
    
    for i = 1: length(label)
        if result(i) == 1 && label(i) == 1
            a(volume(i)/xUnit) = a(volume(i)/xUnit) + 1;
        elseif result(i) ~= 1 && label(i) == 1
            c(volume(i)/xUnit) = c(volume(i)/xUnit) + 1;
        elseif result(i) == 1 && label(i) ~= 1
            b(volume(i)/xUnit) = b(volume(i)/xUnit) + 1;
        elseif result(i) ~= 1 && label(i) ~= 1
            d(volume(i)/xUnit) = d(volume(i)/xUnit) + 1;
        end
    end

    color1 = [0 .3 .7];
    color2 = [.8 .1 .1];
    size = 18;

    x = [10; 20; 30];
    TPR = a./(a+c);
    FPR = b./(b+d);
    y = [TPR, FPR];
    z = bar(x, y);

    set(z(1), 'FaceColor', color1);
    set(z(2), 'FaceColor', color2);
    xlabel('Lub Volume (mL)');
    ylabel('TPR / FPR');
    set(get(gca,'XLabel'),'FontSize',size);
    set(get(gca,'YLabel'),'FontSize',size);
    set(gca,'FontSize',size);
    legend('TPR', 'FPR', 'Location', 'NorthEast');
    ylim([0 1]);
end

%%TPR-Distance (normal interference multipath)
if type == 3
   % figure;
    %% normal
    %subplot(1, 3, 1);
    m = load("result/result-" + filenames(type) + ".mat");
    result = m.result;
    m = load("new_data/" + filenames(type) + ".mat");
    label = m.label;
    distance = m.dis;
    
    a = [0; 0; 0];
    b = [0; 0; 0];
    c = [0; 0; 0];
    d = [0; 0; 0];
    
    xUnit = 50;
    
    for i = 1: length(label)
        if result(i) == 1 && label(i) == 1
            a(distance(i)/xUnit) = a(distance(i)/xUnit) + 1;
        elseif result(i) ~= 1 && label(i) == 1
            c(distance(i)/xUnit) = c(distance(i)/xUnit) + 1;
        elseif result(i) == 1 && label(i) ~= 1
            b(distance(i)/xUnit) = b(distance(i)/xUnit) + 1;
        elseif result(i) ~= 1 && label(i) ~= 1
            d(distance(i)/xUnit) = d(distance(i)/xUnit) + 1;
        end
    end

    color1 = [0 .3 .7];
    color2 = [.8 .1 .1];
    size = 18;

    x = [50; 100; 150];
    TPR = a./(a+c);
    FPR = b./(b+d);
    y = [TPR, FPR];
    z = plot(x, y);

    set(z(1), 'LineStyle', '-', 'Color', color1,'LineWidth',3);
    set(z(2), 'LineStyle', '-', 'Color', color2,'LineWidth',3);
    xlabel('Distance (cm)');
    ylabel('TPR / FPR');
    set(get(gca,'XLabel'),'FontSize',size);
    set(get(gca,'YLabel'),'FontSize',size);
    set(gca,'FontSize',size);
    legend('TPR', 'FPR', 'Location', 'NorthEast');
    ylim([0 1]);
    
    %% interference
    %subplot(1, 3, 2);
    figure;
    m = load("result/result-" + filenames(type+1) + ".mat");
    result = m.result;
    m = load("new_data/" + filenames(type+1) + ".mat");
    label = m.label;
    distance = m.dis;
    
    a = [0; 0; 0];
    b = [0; 0; 0];
    c = [0; 0; 0];
    d = [0; 0; 0];
    
    xUnit = 50;
    
    for i = 1: length(label)
        if result(i) == 1 && label(i) == 1
            a(distance(i)/xUnit) = a(distance(i)/xUnit) + 1;
        elseif result(i) ~= 1 && label(i) == 1
            c(distance(i)/xUnit) = c(distance(i)/xUnit) + 1;
        elseif result(i) == 1 && label(i) ~= 1
            b(distance(i)/xUnit) = b(distance(i)/xUnit) + 1;
        elseif result(i) ~= 1 && label(i) ~= 1
            d(distance(i)/xUnit) = d(distance(i)/xUnit) + 1;
        end
    end

    color1 = [0 .3 .7];
    color2 = [.8 .1 .1];
    size = 18;

    x = [50; 100; 150];
    TPR = a./(a+c);
    FPR = b./(b+d);
    y = [TPR, FPR];
    z = plot(x, y);

    set(z(1), 'LineStyle', '-', 'Color', color1,'LineWidth',3);
    set(z(2), 'LineStyle', '-', 'Color', color2,'LineWidth',3);
    xlabel('Distance (cm)');
    ylabel('TPR / FPR');
    set(get(gca,'XLabel'),'FontSize',size);
    set(get(gca,'YLabel'),'FontSize',size);
    set(gca,'FontSize',size);
    legend('TPR', 'FPR', 'Location', 'NorthEast');
    ylim([0 1]);
    
    %% multipath
    %subplot(1, 3, 3);
    figure;
    m = load("result/result-" + filenames(type+2) + ".mat");
    result = m.result;
    m = load("new_data/" + filenames(type+2) + ".mat");
    label = m.label;
    distance = m.dis;
    
    a = [0; 0; 0];
    b = [0; 0; 0];
    c = [0; 0; 0];
    d = [0; 0; 0];
    
    xUnit = 50;
    
    for i = 1: length(label)
        if result(i) == 1 && label(i) == 1
            a(distance(i)/xUnit) = a(distance(i)/xUnit) + 1;
        elseif result(i) ~= 1 && label(i) == 1
            c(distance(i)/xUnit) = c(distance(i)/xUnit) + 1;
        elseif result(i) == 1 && label(i) ~= 1
            b(distance(i)/xUnit) = b(distance(i)/xUnit) + 1;
        elseif result(i) ~= 1 && label(i) ~= 1
            d(distance(i)/xUnit) = d(distance(i)/xUnit) + 1;
        end
    end

    color1 = [0 .3 .7];
    color2 = [.8 .1 .1];
    size = 18;

    x = [50; 100; 150];
    TPR = a./(a+c);
    FPR = b./(b+d);
    y = [TPR, FPR];
    z = plot(x, y);

    set(z(1), 'LineStyle', '-', 'Color', color1,'LineWidth',3);
    set(z(2), 'LineStyle', '-', 'Color', color2,'LineWidth',3);
    xlabel('Distance (cm)');
    ylabel('TPR / FPR');
    set(get(gca,'XLabel'),'FontSize',size);
    set(get(gca,'YLabel'),'FontSize',size);
    set(gca,'FontSize',size);
    legend('TPR', 'FPR', 'Location', 'NorthEast');
    ylim([0 1]);
end

%%WINDOW_K
if type == 4
    window_Ks = [2; 3; 4; 5; 6; 7; 8; 9; 10];
    simpleHMMfiles = ["test1", "train1"];
    a = zeros(length(window_Ks), 1);
    b = zeros(length(window_Ks), 1);
    c = zeros(length(window_Ks), 1);
    d = zeros(length(window_Ks), 1);
    time = zeros(length(window_Ks), 1);
    
    for k = 1: length(window_Ks)
        for i = 1: length(simpleHMMfiles)
            m = load("result/HMMresult-" + num2str(window_Ks(k)) + "-" + simpleHMMfiles(i) + ".mat");
            result = m.result;
            time(k) = time(k) + m.time;
            m = load("new_data/" + simpleHMMfiles(i) + ".mat");
            label = m.label;
            for j = 1: length(label)
                if result(j) == 1 && label(j) == 1
                    a(k) = a(k) + 1;
                elseif result(j) ~= 1 && label(j) == 1
                    c(k) = c(k) + 1;
                elseif result(j) == 1 && label(j) ~= 1
                    b(k) = b(k) + 1;
                elseif result(j) ~= 1 && label(j) ~= 1
                    d(k) = d(k) + 1;
                end
            end
        end  
    end
    
    figure;

    color1 = [0 .3 .7];
    color2 = [.8 .1 .1];
    color3 = [.4 .4 .4];
    size = 18;

    x = window_Ks;
    TPR = a./(a+c);
    FPR = b./(b+d);
    y = [TPR, FPR];
    %z = bar(x, y);
    
    [hAxes,hBar,hLine]=plotyy(x,y,x,time,'bar','plot');
    
    set(hBar(1), 'FaceColor', color1);
    set(hBar(2), 'FaceColor', color2);
    set(hLine(1), 'LineStyle', '--', 'Color', color3,'LineWidth',3);
    ylabel(hAxes(1), 'TPR / FPR');
    ylabel(hAxes(2), 'Time (s)');
    xlabel('Window Size');
    set(get(gca,'XLabel'),'FontSize',size);
    set(get(hAxes(1),'YLabel'),'FontSize',size);
    set(get(hAxes(2),'YLabel'),'FontSize',size);
    set(hAxes(1),'FontSize',size);
    set(hAxes(2),'FontSize',size);
    legend('TPR', 'FPR', 'Location', 'NorthEast');
    ylim([0 1]);
end